package cn.ichiva.luckysheet.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * TODO
 *
 * @author pzq
 * @version 1.0
 * @date 2022/1/20 15:59
 */
public class LuckeyJimuUtil {
    public static void main(String[] args) {
        String moban_yuanshi_01="[{\"name\":\"Cell\",\"index\":\"sheet_01\",\"order\":0,\"status\":1,\"celldata\":[{\"r\":1,\"c\":1,\"v\":{\"ct\":{\"fa\":\"General\",\"t\":\"g\"},\"m\":\"纵向员工信息登记表\",\"v\":\"纵向员工信息登记表\",\"mc\":{\"r\":1,\"c\":1,\"rs\":1,\"cs\":6},\"ht\":\"0\",\"bl\":1,\"bg\":\"#fff2cc\"}},{\"r\":1,\"c\":2,\"v\":{\"ct\":{\"fa\":\"General\",\"t\":\"g\"},\"mc\":{\"r\":1,\"c\":1},\"ht\":\"0\",\"bl\":1,\"m\":\" \",\"bg\":\"#fff2cc\"}},{\"r\":1,\"c\":3,\"v\":{\"ct\":{\"fa\":\"General\",\"t\":\"g\"},\"mc\":{\"r\":1,\"c\":1},\"ht\":\"0\",\"bl\":1,\"m\":\" \",\"bg\":\"#fff2cc\"}},{\"r\":1,\"c\":4,\"v\":{\"ct\":{\"fa\":\"General\",\"t\":\"g\"},\"mc\":{\"r\":1,\"c\":1},\"ht\":\"0\",\"bl\":1,\"m\":\" \",\"bg\":\"#fff2cc\"}},{\"r\":1,\"c\":5,\"v\":{\"ct\":{\"fa\":\"General\",\"t\":\"g\"},\"mc\":{\"r\":1,\"c\":1},\"ht\":\"0\",\"bl\":1,\"m\":\" \",\"bg\":\"#fff2cc\"}},{\"r\":1,\"c\":6,\"v\":{\"ct\":{\"fa\":\"General\",\"t\":\"g\"},\"mc\":{\"r\":1,\"c\":1},\"ht\":\"0\",\"bl\":1,\"m\":\" \",\"bg\":\"#fff2cc\"}},{\"r\":2,\"c\":1,\"v\":{\"ct\":{\"fa\":\"General\",\"t\":\"g\"},\"m\":\"部门\",\"v\":\"部门\",\"bg\":\"#97c638\"}},{\"r\":2,\"c\":2,\"v\":{\"ct\":{\"fa\":\"General\",\"t\":\"g\"},\"m\":\"学历\",\"v\":\"学历\",\"bg\":\"#97c638\"}},{\"r\":2,\"c\":3,\"v\":{\"ct\":{\"fa\":\"General\",\"t\":\"g\"},\"m\":\"性别\",\"v\":\"性别\",\"bg\":\"#97c638\"}},{\"r\":2,\"c\":4,\"v\":{\"ct\":{\"fa\":\"General\",\"t\":\"g\"},\"m\":\"年龄\",\"v\":\"年龄\",\"bg\":\"#97c638\"}},{\"r\":2,\"c\":5,\"v\":{\"ct\":{\"fa\":\"General\",\"t\":\"g\"},\"m\":\"姓名\",\"v\":\"姓名\",\"bg\":\"#97c638\"}},{\"r\":2,\"c\":6,\"v\":{\"ct\":{\"fa\":\"General\",\"t\":\"g\"},\"m\":\"薪水\",\"v\":\"薪水\",\"bg\":\"#97c638\"}},{\"r\":3,\"c\":1,\"v\":{\"m\":\"#{tt.group(department)}\",\"ct\":{\"fa\":\"@\",\"t\":\"s\"},\"v\":\"#{tt.group(department)}\"}},{\"r\":3,\"c\":2,\"v\":{\"m\":\"#{tt.group(education)}\",\"ct\":{\"fa\":\"@\",\"t\":\"s\"},\"v\":\"#{tt.group(education)}\"}},{\"r\":3,\"c\":3,\"v\":{\"m\":\"#{tt.sex}\",\"ct\":{\"fa\":\"@\",\"t\":\"s\"},\"v\":\"#{tt.sex}\"}},{\"r\":3,\"c\":4,\"v\":{\"m\":\"#{tt.age}\",\"ct\":{\"fa\":\"@\",\"t\":\"s\"},\"v\":\"#{tt.age}\"}},{\"r\":3,\"c\":5,\"v\":{\"m\":\"#{tt.name}\",\"ct\":{\"fa\":\"@\",\"t\":\"s\"},\"v\":\"#{tt.name}\"}},{\"r\":3,\"c\":6,\"v\":{\"m\":\"#{tt.salary}\",\"ct\":{\"fa\":\"@\",\"t\":\"s\"},\"v\":\"#{tt.salary}\"}},{\"r\":9,\"c\":4,\"v\":{\"ct\":{\"fa\":\"General\",\"t\":\"g\"}}}],\"jfgird_select_save\":[],\"luckysheet_select_save\":[{\"left\":393,\"width\":167,\"top\":178,\"height\":19,\"left_move\":393,\"width_move\":167,\"top_move\":178,\"height_move\":19,\"row\":[9,9],\"column\":[3,3],\"row_focus\":9,\"column_focus\":3}],\"config\":{\"merge\":{\"1_1\":{\"r\":1,\"c\":1,\"rs\":1,\"cs\":6}},\"borderInfo\":[{\"rangeType\":\"cell\",\"value\":{\"row_index\":9,\"col_index\":2,\"l\":{\"style\":1,\"color\":\"#6bdd7e\"},\"r\":{\"style\":1,\"color\":\"#6bdd7e\"},\"t\":{\"style\":1,\"color\":\"#6bdd7e\"},\"b\":{\"style\":1,\"color\":\"#6bdd7e\"}}},{\"rangeType\":\"range\",\"borderType\":\"border-all\",\"color\":\"#000\",\"style\":\"1\",\"range\":[{\"left\":74,\"width\":1017,\"top\":17,\"height\":20,\"left_move\":74,\"width_move\":1017,\"top_move\":18,\"height_move\":59,\"row\":[1,3],\"column\":[1,6],\"row_focus\":1,\"column_focus\":1}]}],\"rowlen\":{\"0\":17},\"rowhidden\":{},\"customHeight\":{\"0\":1},\"columnlen\":{\"1\":133,\"2\":184,\"3\":167,\"4\":167,\"5\":216,\"6\":145},\"customWidth\":{\"1\":1,\"2\":1,\"3\":1,\"5\":1,\"6\":1}},\"ch_width\":5134,\"rh_height\":1758,\"luckysheet_selection_range\":[],\"zoomRatio\":1,\"dynamicArray\":[],\"images\":{},\"scrollLeft\":0,\"scrollTop\":0,\"calcChain\":[],\"filter_select\":null,\"filter\":null,\"luckysheet_conditionformat_save\":[],\"luckysheet_alternateformat_save\":[],\"dataVerification\":{},\"hyperlink\":{},\"visibledatarow\":[18,38,58,78,98,118,138,158,178,198,218,238,258,278,298,318,338,358,378,398,418,438,458,478,498,518,538,558,578,598,618,638,658,678,698,718,738,758,778,798,818,838,858,878,898,918,938,958,978,998,1018,1038,1058,1078,1098,1118,1138,1158,1178,1198,1218,1238,1258,1278,1298,1318,1338,1358,1378,1398,1418,1438,1458,1478,1498,1518,1538,1558,1578,1598,1618,1638,1658,1678],\"visibledatacolumn\":[74,208,393,561,729,946,1092,1166,1240,1314,1388,1462,1536,1610,1684,1758,1832,1906,1980,2054,2128,2202,2276,2350,2424,2498,2572,2646,2720,2794,2868,2942,3016,3090,3164,3238,3312,3386,3460,3534,3608,3682,3756,3830,3904,3978,4052,4126,4200,4274,4348,4422,4496,4570,4644,4718,4792,4866,4940,5014]},{\"name\":\"Data\",\"index\":\"sheet_02\",\"order\":1,\"status\":0,\"celldata\":[],\"luckysheet_select_save\":[{\"row\":[0,0],\"column\":[0,0],\"row_focus\":0,\"column_focus\":0,\"left\":0,\"width\":73,\"top\":0,\"height\":19,\"left_move\":0,\"width_move\":73,\"top_move\":0,\"height_move\":19}],\"config\":{},\"visibledatarow\":[20,40,60,80,100,120,140,160,180,200,220,240,260,280,300,320,340,360,380,400,420,440,460,480,500,520,540,560,580,600,620,640,660,680,700,720,740,760,780,800,820,840,860,880,900,920,940,960,980,1000,1020,1040,1060,1080,1100,1120,1140,1160,1180,1200,1220,1240,1260,1280,1300,1320,1340,1360,1380,1400,1420,1440,1460,1480,1500,1520,1540,1560,1580,1600,1620,1640,1660,1680],\"visibledatacolumn\":[74,148,222,296,370,444,518,592,666,740,814,888,962,1036,1110,1184,1258,1332,1406,1480,1554,1628,1702,1776,1850,1924,1998,2072,2146,2220,2294,2368,2442,2516,2590,2664,2738,2812,2886,2960,3034,3108,3182,3256,3330,3404,3478,3552,3626,3700,3774,3848,3922,3996,4070,4144,4218,4292,4366,4440],\"ch_width\":4560,\"rh_height\":1760,\"luckysheet_selection_range\":[],\"scrollLeft\":0,\"scrollTop\":0,\"zoomRatio\":1},{\"name\":\"Picture\",\"index\":\"sheet_03\",\"order\":2,\"status\":0,\"celldata\":[]}]";
        JSONArray jsonArray = (JSONArray) JSONObject.parse(moban_yuanshi_01);
        //如果只有一个sheet那就是get(0),有多个那就对应取下标
        JSONObject jsonObject = (JSONObject) jsonArray.get(0);
        JSONArray jsonObjectList = jsonObject.getJSONArray("celldata");
        List<Integer> list = new ArrayList<>();
        for(int i=0;i<jsonObjectList.size();i++) {
            String r=jsonObjectList.getJSONObject(i).get("r").toString();
            String c=jsonObjectList.getJSONObject(i).get("c").toString();
            if(!list.contains(Integer.valueOf(r))){
                list.add(Integer.valueOf(r));
            }
//            JSONObject jsonObject1 =JSONObject.parseObject(v);
//            JSONObject r=(JSONObject)jsonObjectList.getJSONObject(i).get("r");
//            JSONObject c=(JSONObject)jsonObjectList.getJSONObject(i).get("c");
            System.out.println(r+c);
        }
        JSONArray jsonArray1=new JSONArray();
        Map<String,Object> mapw= new HashMap();
        for (int i = 0; i < list.size(); i++) {
            int row=list.get(i);
            Map<String,Object> map =  new HashMap();
            Map<String,Object> map1 =new HashMap();
            for (int j = 0; j < jsonObjectList.size(); j++) {
                if(row==(int)jsonObjectList.getJSONObject(j).get("r")){
                    Map mapvalue =new HashMap();
                    JSONObject jsonObjectv=(JSONObject)jsonObjectList.getJSONObject(j).get("v");
                    mapvalue.put("text",jsonObjectv.get("m"));
                    mapvalue.put("style","150");
                    map1.put(String.valueOf(jsonObjectList.getJSONObject(j).get("c")),mapvalue);
//                    listmap.add(map1);
                }
            }
            map.put("cells",map1);
            mapw.put(String.valueOf(row),map);
        }
        String jsonString = JSON.toJSONString(mapw);

        System.out.println(jsonArray1.toString());
    }
}
